package cn.ming.leo.resource.manager;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.ming.leo.bean.User;
import cn.ming.leo.bean.vo.RequestJson;
import cn.ming.leo.service.UserService;
import cn.ming.leo.utils.Message;
import cn.ming.leo.utils.PageListModel;

@RestController
@RequestMapping("/m/user")
public class MUserResource {

	@Autowired
	private UserService userService;

	@RequestMapping(value = "/remove", method = RequestMethod.POST)
	@ResponseBody
	public Message<String> remove(@RequestBody RequestJson json) {
		return userService.remove(json.getUserId());
	}

	@RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
	@ResponseBody
	public Message<String> updateStatus(@RequestBody RequestJson json) {
		return userService.updateStatus(json.getUserId(), json.getStatus());
	}

	@RequestMapping(value = "/updateFlag", method = RequestMethod.POST)
	@ResponseBody
	public Message<String> updateFlag(@RequestBody RequestJson json) {
		return userService.updateFlag(json.getMobile());
	}
	
	@RequestMapping(value = "/transferRole", method = RequestMethod.POST)
	@ResponseBody
	public Message<String> transferRole(@RequestBody RequestJson json) {
		return userService.transferRole(json.getUserId(),json.getMobile());
	}

	@RequestMapping(value = "/updateRoles", method = RequestMethod.POST)
	@ResponseBody
	public Message<String> updateRoles(@RequestBody RequestJson json) {
		return userService.updateRoles(json.getUserId(), json.getRoles());
	}

	@RequestMapping(value = "/findAll", method = RequestMethod.GET)
	public Message<PageListModel<User>> findAll(Integer pageIndex, Integer pageSize) {
		return userService.findAll(pageIndex, pageSize);
	}

	@RequestMapping(value = "/admins", method = RequestMethod.GET)
	public Message<PageListModel<User>> admins(Integer pageIndex, Integer pageSize) {
		return userService.findAll1(pageIndex, pageSize);
	}

	@RequestMapping(value = "/view", method = RequestMethod.GET)
	public Message<Map<String, Object>> getById(int id) {
		return userService.view(id);
	}
}
